Skip to content

[clang][SYCL] Add sycl_external attribute and restrict emitting device code #140282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

schittir
Copy link
Contributor

@schittir schittir commented May 16, 2025

This patch is part of the upstreaming effort for supporting SYCL language front end.
It makes the following changes:

  1. Adds sycl_external attribute for functions with external linkage.
  2. Adds checks to avoid emitting device code when sycl_external and sycl_kernel_entry_point attributes are not enabled
  3. Fixes test failures caused by the above changes

This patch is missing diagnostics for the following diagnostics listed in the SYCL 2020 specification's section 5.10.1, which will be addressed in a subsequent PR:
Functions that are declared using SYCL_EXTERNAL have the following additional restrictions beyond those imposed on other device functions:

  1. If the SYCL backend does not support the generic address space then the function cannot use raw pointers as parameter or return types. Explicit pointer classes must be used instead;
  2. The function cannot call group::parallel_for_work_item;
  3. The function cannot be called from a parallel_for_work_group scope.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @schittir! I completed an initial pass of all of the code, but still need to look more closely at the documentation updates.

@schittir
Copy link
Contributor Author

Thanks for working on this @schittir! I completed an initial pass of all of the code, but still need to look more closely at the documentation updates.

Thank you for the initial pass review, Tom!

Copy link

github-actions bot commented May 26, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@schittir schittir changed the title Add sycl_external attribute [SYCL] Add sycl_external attribute Jun 10, 2025
@schittir schittir marked this pull request as ready for review June 10, 2025 16:16
@schittir schittir changed the title [SYCL] Add sycl_external attribute [clang][SYCL Upstreaming] Add sycl_external attribute Jun 10, 2025
@Fznamznon Fznamznon added the SYCL https://registry.khronos.org/SYCL label Jun 10, 2025
@schittir schittir changed the title [clang][SYCL Upstreaming] Add sycl_external attribute [clang][SYCL Upstreaming] Add sycl_external attribute and restrict emitting code Jun 10, 2025
@schittir schittir changed the title [clang][SYCL Upstreaming] Add sycl_external attribute and restrict emitting code [clang][SYCL Upstreaming] Add sycl_external attribute and restrict emitting device code Jun 10, 2025
@Fznamznon Fznamznon changed the title [clang][SYCL Upstreaming] Add sycl_external attribute and restrict emitting device code [clang][SYCL] Add sycl_external attribute and restrict emitting device code Jun 11, 2025
Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @schittir, here are my initial review comments. I expect to review the newly added tests more closely once these comments are all addressed.

@Fznamznon
Copy link
Contributor

Oops new tests are failing.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good @schittir! I added some comments for minor issues. I still need to review the tests more closely.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments. I still haven't finished my review of sycl-external-attr.cpp, but will try to later today or over the weekend.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I finished an initial pass through all of the tests. I'll do another round once you've had a chance to catch up on the comments so far.

Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great @schittir! I just realized that, since we made the change to allow the attribute to be present during host compilation that we should no longer restrict diagnostics to device compilation and that tests should exercise host compilation as well.

I suggested a few FIXME comments, but other than that, I think this is good to go!

@schittir
Copy link
Contributor Author

This is looking great @schittir! I just realized that, since we made the change to allow the attribute to be present during host compilation that we should no longer restrict diagnostics to device compilation and that tests should exercise host compilation as well.

I suggested a few FIXME comments, but other than that, I think this is good to go!

Thank you for the review, Tom!

@schittir schittir requested a review from tahonermann July 18, 2025 15:49
Copy link
Contributor

@tahonermann tahonermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it @schittir, this looks great!

@erichkeane, @bader, please review and lend your approval. Note that some of the changes to the tests are to synchronize them with continued evolution that happened in DPC++ but was not previously upstreamed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SYCL https://registry.khronos.org/SYCL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants